package com.watermeter.android.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.oa.android.R;
import com.watermeter.android.entry.curstorInfo;
import com.watermeter.android.utils.Util;

import java.util.List;

/**
 * 信息修改上传适配器
 * Created by zouqh on 2016/5/23.
 */
public class UpInfoAdapter extends BaseAdapter {
    private Context context;
    private List<curstorInfo> rowses;

    public UpInfoAdapter(Context context, List<curstorInfo> rowses) {
        this.context = context;
        this.rowses = rowses;
    }

    @Override
    public int getCount() {
        return rowses.size();
    }

    @Override
    public Object getItem(int position) {
        return rowses.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHodler viewHodler;
        if (convertView == null) {
            viewHodler = new ViewHodler();
            convertView = LayoutInflater.from(context).inflate(R.layout.up_info_item, null);
            viewHodler.name = (TextView) convertView.findViewById(R.id.name);
            viewHodler.phone = (TextView) convertView.findViewById(R.id.phone);
            viewHodler.address = (TextView) convertView.findViewById(R.id.address);
            viewHodler.cbxh = (TextView) convertView.findViewById(R.id.cbxh);
            viewHodler.sbbh = (TextView) convertView.findViewById(R.id.sbbh);
            viewHodler.states = (TextView) convertView.findViewById(R.id.states);
            viewHodler.bzxx = (TextView) convertView.findViewById(R.id.bzxx);

            viewHodler.name1 = (TextView) convertView.findViewById(R.id.name1);
            viewHodler.phone1 = (TextView) convertView.findViewById(R.id.phone1);
            viewHodler.address1 = (TextView) convertView.findViewById(R.id.address1);
            viewHodler.cbxh1 = (TextView) convertView.findViewById(R.id.cbxh1);
            viewHodler.sbbh1 = (TextView) convertView.findViewById(R.id.sbbh1);
            viewHodler.states1 = (TextView) convertView.findViewById(R.id.states1);
            viewHodler.bzxx1 = (TextView) convertView.findViewById(R.id.bzxx1);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }
        curstorInfo info=rowses.get(position);
        viewHodler.name.setText("客户姓名：" + info.getUSERNAME());
        viewHodler.phone.setText("客户电话：" +info.getLXDH() );
        viewHodler.address.setText("详细地址：" +info.getXXDZ());
        viewHodler.cbxh.setText("抄表序号：" +info.getCBXH());
        viewHodler.sbbh.setText("水表编号：" +info.getSBBH());
        viewHodler.states.setText("水表状态：" +info.getSBZT());
        viewHodler.bzxx.setText("备注信息：" +info.getBZXX());
        if (Util.NoNull(info.getNUSERNAME())){
            if (!info.getNUSERNAME().equals(info.getUSERNAME())){
                viewHodler.name1.setText("上次修改：" + info.getNUSERNAME());
            }
        }
        if (Util.NoNull(info.getNLXDH())){
            if (!info.getNLXDH().equals(info.getLXDH())){
                viewHodler.phone1.setText("上次修改：" + info.getNLXDH());
            }
        }
        if (Util.NoNull(info.getNXXDZ())){
            if (!info.getNXXDZ().equals(info.getXXDZ())){
                viewHodler.address1.setText("上次修改：" + info.getNXXDZ());
            }
        }
        if (Util.NoNull(info.getNCBXH())){
            if (!info.getNCBXH().equals(info.getCBXH())){
                viewHodler.cbxh1.setText("上次修改：" + info.getNCBXH());
            }
        }
        if (Util.NoNull(info.getNSBBH())){
            if (!info.getNSBBH().equals(info.getSBBH())){
                viewHodler.sbbh1.setText("上次修改：" + info.getNSBBH());
            }
        }

        if (Util.NoNull(info.getNSBZT())){
            if (!info.getNSBZT().equals(info.getSBZT())){
                viewHodler.states1.setText("上次修改：" + info.getNSBZT());
            }
        }
        if (Util.NoNull(info.getNBZXX())){
            if (!info.getNBZXX().equals(info.getBZXX())){
                viewHodler.bzxx1.setText("上次修改：" + info.getNBZXX());
                viewHodler.bzxx1.setVisibility(View.VISIBLE);
            }else{
                viewHodler.bzxx1.setVisibility(View.GONE);
            }
        }else{
            viewHodler.bzxx1.setVisibility(View.GONE);
        }

        return convertView;
    }

    class ViewHodler {
        TextView name;
        TextView phone;
        TextView address;
        TextView sbbh;
        TextView cbxh;
        TextView states;
        TextView bzxx;

        TextView name1;
        TextView phone1;
        TextView address1;
        TextView sbbh1;
        TextView cbxh1;
        TextView states1;
        TextView bzxx1;

    }
}
